package com.octopus.yangj.customized.service;

import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.octopus.kernal.service.ConfigService;
import com.octopus.yangj.generated.model.EmployeeStruct;
import com.octopus.yangj.generated.model.SystemLogStruct;
import com.octopus.yangj.generated.service.SystemLogService;

@Service("logService")
public class LogService{
	
	@Autowired
	private SystemLogService service;
	
	public void log(String model, String action, Object message){
		String on = ConfigService.getInstance().getProperty("system.log");
		if(StringUtils.isBlank(on) || !Boolean.valueOf(on))
			return;
		EmployeeStruct user = (EmployeeStruct)SecurityUtils.getSubject().getSession().getAttribute("currentUser");
		SystemLogStruct log = new SystemLogStruct();
		log.setUsername(null==user?"system":user.getUsername());
		log.setLogDate(new Date());
		log.setModule(model);
		log.setAction(action);
		log.setMessage(null==message?"":String.valueOf(message));
		service.createEntity(log);
	}

}
